import { Injectable } from '@angular/core';
import { RequestClientService } from '../request-client.service';
import { TREEURL, CLOUDURL, version } from 'src/app/config';
@Injectable({
  providedIn: 'root'
})
export class DataManagementService {

  public constructor(private reqService: RequestClientService) { }
  public getheaderTenantId() {
    return { TenantId: window.localStorage.getItem('TenantId') };
  }
  public async getExcelCatogery(id) {
    let res = await this.reqService.get(`${CLOUDURL}/api/v${version}/ExcelCatogery`, { ParentId: id, PageSize: 1000 });
    if (res.success) {
      return res;
    } else {
      return false;
    }
  }
  public async getExceltemplate(id) {
    let res = await this.reqService.get(`${CLOUDURL}/api/v${version}/ExcelTemplate`, { CategoryId: id, PageSize: 1000 });
    if (res.success) {
      return res;
    } else {
      return false;
    }
  }
  public async getExlTemplateById(id) {
    let res = await this.reqService.get(`${CLOUDURL}/api/v${version}/ExcelTemplate/` + id, {});
    if (res.success) {
      return res;
    } else {
      return false;
    }
  }
  public async getExcel(id) {
    let res = await this.reqService.get(`${TREEURL}/api/v${version}/Excel`, { TemplateId: id, PageSize: 1000 }, this.getheaderTenantId());
    if (res.success) {
      return res;
    } else {
      return false;
    }
  }
  public async addExlFolder(Json) {
    let res = await this.reqService.post(`${CLOUDURL}/api/v${version}/ExcelCatogery`, Json);
    if (res.success) {
      return res;
    } else {
      return false;
    }
  }
  public async addExlTemplate(Json) {
    let res = await this.reqService.post(`${CLOUDURL}/api/v${version}/ExcelTemplate`, Json);
    if (res.success) {
      return res;
    } else {
      return false;
    }
  }
  public async addExl(Json) {
    let res = await this.reqService.post(`${TREEURL}/api/v${version}/Excel`, Json, this.getheaderTenantId());
    if (res.success) {
      return res;
    } else {
      return false;
    }
  }
  public async delExl(Json) {
    let res = await this.reqService.delete(`${TREEURL}/api/v${version}/Excel`, Json, this.getheaderTenantId());
    if (res.success) {
      return res;
    } else {
      return false;
    }
  }
  // 添加视点
  public async editView(Json) {
    let res = await this.reqService.post(`${TREEURL}/api/v${version}/ViewPort/AddViewPort`, Json, this.getheaderTenantId());
    if (res.success) {
      return true;
    } else {
      return false;
    }
  }
  // 删除视点
  public async deleteView(id) {
    let res = await this.reqService.delete(`${TREEURL}/api/v${version}/ViewPort/RemoveViewPort?id=` + id, this.getheaderTenantId());
    if (res.success) {
      return true;
    } else {
      return false;
    }
  }
  // 修改视点
  public async changeView(Json) {
    let res = await this.reqService.put(`${TREEURL}/api/v${version}/ViewPort/UpdateViewPort`, Json , this.getheaderTenantId());
    if (res.success) {
      return true;
    } else {
      return false;
    }
  }
  // 查询视点
  public async queryView(req) {
    let res = await this.reqService.get(`${TREEURL}/api/v${version}/ViewPort/Get`, {ModelGroupId : req}, this.getheaderTenantId());
    if (res.success) {
      return res;
    } else {
      return false;
    }
  }
}
